﻿namespace Api;

/// <summary>
/// 昵称头像生成
/// </summary>
public class NickName
{
    private async static Task<string> GetAvatar()
    {
        string url = $"https://cn.apihz.cn/api/img/apihzimgtx.php?id=10002707&key=3515f64590f88e6dff31f1565132ddf1&type=1";

        var res = await Http.Get<dynamic>(url);

        if (res == null) return "https://res.apihz.cn/img/tx/15aaea1b9acad29328f7250a30859815.jpg";

        if (res.code != 200) return "https://res.apihz.cn/img/tx/15aaea1b9acad29328f7250a30859815.jpg";

        return res.msg;
    }

    private async static Task<string> GetName()
    {
        string url = $"https://cn.apihz.cn/api/zici/sjwm.php?id=10002707&key=3515f64590f88e6dff31f1565132ddf1";

        var res = await Http.Get<dynamic>(url);

        if (res == null) return "微信用户";

        if (res.code != 200) return "微信用户";

        return res.msg;
    }

    /// <summary>
    /// 获取随机头像和昵称
    /// </summary>
    /// <returns></returns>
    public async static Task<(string, string)> Get()
    {
        var name = await GetName();

        var avatar = await GetAvatar();

        return (name, avatar);
    }
}
